/**
 * ResultUI.java
 * FlightBookingCentre
 * Phillip
 * 2014��3��22�� ����2:05:16
 */
package com.view.client;

import com.dao.Flight;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

/**
 * @author Phillip
 */
public class ResultUI extends JFrame {

    private Flight flight1;
    private Flight flight2;
    private JLabel depart;
    private JLabel flight;
    private JLabel arrive;
    private JLabel city11;
    private JLabel city12;
    private JLabel city21;
    private JLabel city22;
    private JLabel airport11;
    private JLabel airport12;
    private JLabel airport21;
    private JLabel airport22;
    private JLabel departDate1;
    private JLabel departDate2;
    private JLabel arriveDate1;
    private JLabel arriveDate2;
    private JLabel departTime1;
    private JLabel arriveTime2;
    private JLabel departTime2;
    private JLabel arriveTime1;
    private JLabel airline1;
    private JLabel airline2;
    private JLabel flightNo1;
    private JLabel flightNo2;
    private JLabel class1;
    private JLabel class2;
    private JLabel plane1;
    private JLabel plane2;
    private JLabel blankLabel1;
    private JLabel blankLabel2;
    private JLabel blankLabel3;
    private JButton button;

    public ResultUI(List<Flight> flights) {

        this.flight1 = flights.get(0);
        this.flight2 = flights.get(1);

        this.setTitle("MY FLIGHT BOOKING CENTRE");
        this.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        this.setSize(500, 500);
        this.setResizable(false);

        depart = new JLabel("       DEPART");
        depart.setBackground(Color.CYAN);
        depart.setOpaque(true);
        flight = new JLabel("       FLIGHT INFO");
        flight.setBackground(Color.CYAN);
        flight.setOpaque(true);
        arrive = new JLabel("         ARRIVE");
        arrive.setBackground(Color.CYAN);
        arrive.setOpaque(true);

        city11 = new JLabel(flight1.getDeptCityString());
        city12 = new JLabel(flight1.getDeptCityString());
        airport11 = new JLabel(flight1.getDeptAirportString());
        airport12 = new JLabel(flight1.getDeptAirportString());
        departDate1 = new JLabel("TODO");
        departTime1 = new JLabel(flight1.getDeptTime().toString());
        city21 = new JLabel(flight2.getDeptCityString());
        city22 = new JLabel(flight2.getDeptCityString());
        airport21 = new JLabel(flight1.getArriAirportString());
        airport22 = new JLabel(flight1.getArriAirportString());
        departDate2 = new JLabel("TODO");
        departTime2 = new JLabel(flight2.getDeptTime().toString());
        airline1 = new JLabel(flight1.getAirlineString());
        airline2 = new JLabel(flight1.getAirlineString());
        flightNo1 = new JLabel(flight1.getFligthNOString());
        class1 = new JLabel(flight1.getClassEnum().toString());
        flightNo2 = new JLabel(flight2.getFligthNOString());
        class2 = new JLabel(flight2.getClassEnum().toString());
        arriveDate1 = new JLabel("TODO");
        arriveDate2 = new JLabel("TODO");
        arriveTime1 = new JLabel(flight1.getArriTime().toString());
        arriveTime2 = new JLabel(flight2.getArriTime().toString());
        plane1 = new JLabel(flight1.getPlaneString());
        plane2 = new JLabel(flight2.getPlaneString());
        blankLabel1 = new JLabel();
        blankLabel2 = new JLabel();
        blankLabel3 = new JLabel();

        button = new JButton("Book Successfully, Press to quit!");
        button.addActionListener(new ButtonHandler());

        c.fill = GridBagConstraints.BOTH;
        c.gridx = 0;
        c.gridy = 0;
        c.insets = new Insets(10, 0, 10, 0);
        this.add(depart, c);

        c.gridx = 1;
        this.add(flight, c);

        c.gridx = 2;
        this.add(arrive, c);

        c.gridx = 0;
        c.gridy = 1;
        c.insets = new Insets(0, 20, 0, 20);
        this.add(city11, c);

        c.gridx = 1;
        this.add(airline1, c);

        c.gridx = 2;
        this.add(city21, c);

        c.gridx = 0;
        c.gridy = 2;
        this.add(airport11, c);

        c.gridx = 1;
        this.add(flightNo1, c);

        c.gridx = 2;
        this.add(airport21, c);

        c.gridx = 0;
        c.gridy = 3;
        this.add(departDate1, c);

        c.gridx = 1;
        this.add(class1, c);

        c.gridx = 2;
        this.add(arriveDate1, c);

        c.gridx = 0;
        c.gridy = 4;
        this.add(departTime1, c);

        c.gridx = 1;
        this.add(plane1, c);

        c.gridx = 2;
        this.add(arriveTime1, c);

        c.gridx = 0;
        c.gridy = 5;
        this.add(blankLabel1, c);

        c.gridx = 1;
        this.add(blankLabel2, c);

        c.gridx = 2;
        this.add(blankLabel3, c);

        c.gridx = 0;
        c.gridy = 6;
        c.insets = new Insets(15, 20, 0, 20);
        this.add(city22, c);

        c.gridx = 1;
        this.add(airline2, c);

        c.gridx = 2;
        this.add(city12, c);

        c.gridx = 0;
        c.gridy = 7;
        c.insets = new Insets(0, 20, 0, 20);
        this.add(airport22, c);

        c.gridx = 1;
        this.add(flightNo2, c);

        c.gridx = 2;
        this.add(airport12, c);

        c.gridx = 0;
        c.gridy = 8;
        this.add(departDate2, c);

        c.gridx = 1;
        this.add(class2, c);

        c.gridx = 2;
        this.add(arriveDate2, c);

        c.gridx = 0;
        c.gridy = 9;
        this.add(departTime2, c);

        c.gridx = 1;
        this.add(plane2, c);

        c.gridx = 2;
        this.add(arriveTime2, c);

        c.gridx = 0;
        c.gridy = 10;
        c.gridwidth = 3;
        c.insets = new Insets(30, 0, 10, 0);
        this.add(button, c);

        this.setVisible(true);
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
    }

    private class ButtonHandler implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            dispose();
        }

    }

}
